﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain.SellerKpi;
using LX.Web.Excel;

namespace S4Store.Domain.Report
{
    public class SellerPersonBrandReport : SellerCommonReport
    {

        #region 导出
        [Export("销售顾问名称",MergeVertical=true)]
        public string SellerName
        {
            get { return Seller.Name; }
        }
        [Export("车型")]
        public string CarBrandName
        {
            get { return CarBrand.Name; }
        }
        #endregion

        public Employee Seller { get; set; }
        public CarBrand CarBrand { get; set; }
        public CommonSellerKpi.CommonSellerMonthConfig SellerMonthConfig { get; set; }
        public List<CommonSellerKpi.CommonSellerKpiDayData> SellerKpiDayDatas { get; set; }

        /// <summary>
        /// 店总计报告
        /// </summary>
        public SellerReport StoreReport { get; set; }

        /// <summary>
        /// 月初尚存意向客户数
        /// </summary>
        [Export("月初尚存意向客户数")]
        public override int LastMonthPotentialClient
        {
            get
            {
                return SellerMonthConfig.LastMonthPotentialClient;
            }
        }
        /// <summary>
        /// 累计订单数
        /// </summary>
        [Export("订单数")]
        public override int OrderCount
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.DYKHXZDD + t.SYYLKHXZDD);
            }
        } 
        /// <summary>
        /// 累计交车数
        /// </summary>
        [Export("交车数")]
        public override int SaleCount
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.JCS);
            }
        }
        /// <summary>
        /// 销售目标
        /// </summary>
        [Export("销售目标")]
        public override int SaleTarget
        {
            get
            {
                return SellerMonthConfig.SaleTarget;
            }
        }
        /// <summary>
        /// 首   次   来   店  客   户   登   记   数
        /// </summary>
        [Export("首次来店客户登记数")]
        public override int SCLDKHDJS
        {
            get { return SellerKpiDayDatas.Sum(t => t.SCLDKHDJS); }
        }
        /// <summary>
        /// 首   次   来   店  接   待   批   次
        /// </summary>
        [Export("首次来店接待批次")]
        public override int LDJDPC
        {
            get { return SellerKpiDayDatas.Sum(t => t.LDJDPC); }
        }

        /// <summary>
        /// 试  驾  邀  请  书  填  写  数
        /// </summary>
        [Export("试驾邀请书填写数")]
        public override int SJYQSTXS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.SJYQSTXS);
            }
        }
        /// <summary>
        /// 试  驾  客  户   成   交   数
        /// </summary>
        [Export("试驾客户未成交数")]
        public override int SJKHCJS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.SJKHCJS);
            }
        }
        /// <summary>
        /// 上月遗留客户新增订单
        /// </summary>
        [Export("上月遗留客户新增订单")]
        public override int SYYLKHXZDD
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.SYYLKHXZDD);
            }
        }
        /// <summary>
        /// 超   限   价   格   成   交   数
        /// </summary>
        [Export("超限价格成交数")]
        public override int CXJGCJS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.CXJGCJS);
            }
        }
        /// <summary>
        /// 首   次   来   店     登   记   数  目  标
        /// </summary>
        [Export("首次来店登记数目标")]
        public override int SCLDDJMB
        {
            get
            {
                if (this.SellerKpiMonthConfig.LastMonthAvgvr == 0)
                {
                    return SaleTarget;
                }
                return ((decimal)SaleTarget * 100 / SellerKpiMonthConfig.LastMonthAvgvr).AutoRound1();
            }
        }

        /// <summary>
        /// 首次来店接待目标
        /// </summary>
        [Export("首次来电接待目标")]
        public override decimal SCLDJDMB
        {
            get
            {
                if (this.StoreReport.SCLDDJLV==0)
                {
                    return SCLDDJMB;
                }
                return (int)(SCLDDJMB * 100 / SellerPerformanceStandard.SCLDDJLV);
            }
        }

        //public override decimal LDHPCWCD {
        //    get {
        //        if (SCLDHJDMB == 0)
        //        {
        //            return 0;
        //        }
        //        return LDJDPC * 100 / SCLDHJDMB;
        //    }
        //}

        public override decimal SCLDHJDMB
        {
            get
            {
                if (this.StoreReport.SCLDDJLV == 0)
                {
                    return SCLDDJMB;
                }
                return (int)(SCLDDJMB * 100 / SellerPerformanceStandard.DHZLDDLV);
            }
        }
        /// <summary>
        /// 有效  A   卡   建卡   数
        /// </summary>
        [Export("有效A卡建卡数")]
        public override decimal YXAKJKS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.YXAKJKS);
            }
        }
        /// <summary>
        /// 商   谈   明   细   表   填   写   数
        /// </summary>
        [Export("商谈明细表填写数")]
        public override decimal STMXBTXS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.STMXBTXS);
            }
        }

        /// <summary>
        /// 二 手 车 评 估 数
        /// </summary>
        [Export("二手车评估数")]
        public override decimal ESCPGS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.ESCPGS);
            }
        }
        /// <summary>
        /// 置 换 成 交 数
        /// </summary>
        [Export("置换成交数")]
        public override decimal ZHCJS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.ZHCJS);
            }
        }
        /// <summary>
        /// 按 揭 成 交 数
        /// </summary>
        [Export("按揭成交数")]
        public override decimal AJCJS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.AJCJS);
            }
        }
        /// <summary>
        /// 当月客户新增订单数
        /// </summary>
        [Export("当月客户新增订单数")]
        public override decimal DYKHXZDD
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.DYKHXZDD);
            }
        }
        /// <summary>
        /// 新   车   保   险   投   保  数
        /// </summary>
        [Export("新车保险投保数")]
        public override decimal XCBXTBS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.XCBXTBS);
            }
        }
        /// <summary>
        /// 保       险       销       售       总      额
        /// </summary>
        [Export("保险销售额")]
        public override decimal BXXSE
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.BXXSE);
            }
        }
        /// <summary>
        /// 套   餐    车 销   售  数   量
        /// </summary>
        [Export("套餐车销售数量")]
        public override decimal TCCXSSL
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.TCCXSSL);
            }
        }
        /// <summary>
        /// 有   效  装 潢   车   销   售   数   量
        /// </summary>
        [Export("有效装潢车销售数量")]
        public override decimal YXZHCXSSL
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.YXZHCXSSL);
            }
        }
        /// <summary>
        /// 装   潢   车     装     潢     销     售          额    （万）
        /// </summary>
        [Export("装潢销售额")]
        public override decimal ZHCZHXSE
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.ZHCZHXSE);
            }
        }
        /// <summary>
        /// 新 车 延 保 数
        /// </summary>
        [Export("新车延保数")]
        public override decimal XCYBS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.XCYBS);
            }
        }
        /// <summary>
        /// 二次   成  功   邀   约   客  户  数
        /// </summary>
        [Export("二次成功邀约客户数")]
        public override decimal ECCGYYKHS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.ECCGYYKHS);
            }
        }
        /// <summary>
        /// 当   月      老 客   户   推   荐  成   交 数
        /// </summary>
        [Export("老客户推荐成交数")]
        public override decimal DYLKHTJCJS
        {
            get
            {
                return SellerKpiDayDatas.Sum(t => t.DYLKHTJCJS);
            }
        }
    }
}
